package com.qls.consumer.biz.controller;

import com.qls.consumer.biz.service.Queue;
import com.qls.core.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @author doyoung
 */
@RestController
public class Controller {

    @Autowired
    private Queue queue;

    /**
     * 给店铺创建队列
     *
     * @param params Map<String, Object>
     * @return R
     */
    @GetMapping("create")
    public R create(@RequestParam Map<String, Object> params) {
        Integer storeId = Integer.valueOf(params.get("storeId").toString());
        boolean flag = queue.create(storeId);
        if (flag) {
            return R.ok();
        }
        return R.error("队列创建失败");
    }

    /**
     * 销毁店铺的队列
     *
     * @param params Map<String, Object>
     * @return R
     */
    @GetMapping("destroy")
    public R destroy(@RequestParam Map<String, Object> params) {
        Integer storeId = Integer.valueOf(params.get("storeId").toString());
        boolean flag = queue.destroy(storeId);
        if (flag) {
            return R.ok();
        }
        return R.error("队列删除失败");
    }
}
